package servlet;

import java.io.IOException;
import java.util.Enumeration;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.FiyatiNeydi;
import model.User;

import com.mongodb.MongoException;

import service.DAO;

/**
 * Servlet implementation class FiyatEkle
 */
@WebServlet("/FiyatEkle")
public class FiyatEkle extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public FiyatEkle() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		// TODO Auto-generated method stub
		/*
		String urun = request.getParameter("urun");
		String market = request.getParameter("maret");
		String fiyatStr = request.getParameter("fiyat");
		String user = request.getParameter("user");
		
		FiyatiNeydi fiyat = new FiyatiNeydi();
		fiyat.setFiyat(Double.valueOf(fiyatStr));
		fiyat.setMarket(market);
		fiyat.setUrun(urun);
		fiyat.setUser(user);
		try {
			DAO.insertFiyat(fiyat);	
		} catch (MongoException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		response.getWriter().write("Eklendi..");
*/
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
	{
//		response.getWriter().write("<p>hello form</p>");
		String urun=request.getParameter("urun");
		String market=request.getParameter("market");
		String fiyatStr=request.getParameter("fiyat");
/*
  		User u = (User) request.getSession().getAttribute("user");
		System.out.println("////////////////////////////////"+u.getName());
		String user=u.getUid();
*/
		String user="Test User";
		FiyatiNeydi fiyat=new FiyatiNeydi(urun, market, user, Double.parseDouble(fiyatStr));
		DAO.insertFiyat(fiyat);
//		response.getWriter().write("eklendi");
		
	}

}
